package sanrenxing.dayEnd.backRepertoryTotal.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sanrenxing.dayEnd.backRepertoryTotal.domain.ExchangeVarietyRate;
import sanrenxing.dayEnd.backRepertoryTotal.service.ExchangeVarietyRateBiz;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/excharcrud")
public class ExchangeVarietyRateController {
    /*定义业务层接口*/
    @Autowired
    private ExchangeVarietyRateBiz exchangeVarietyRateBiz;

    @GetMapping("/exch")
    public Map<String,Object> queryAll(int page, int limit, ExchangeVarietyRate exchangeVarietyRate){
        Map<String,Object> map=new HashMap<>();
        map.put("code",0);
        map.put("msg","");
        map.put("count",exchangeVarietyRateBiz.count(exchangeVarietyRate));
        map.put("data",exchangeVarietyRateBiz.queryAll(exchangeVarietyRate,limit,(page-1)*limit));
        return map;
    }
    //添加数据
    @PostMapping("/exch")
    public String addFund(@RequestBody ExchangeVarietyRate exchangeVarietyRate) {
        int rows=exchangeVarietyRateBiz.add(exchangeVarietyRate);
        return rows>0?"add success":"failure";
    }

    //删除数据
    @DeleteMapping("/exch/{str}")
    public String deleteFund(@PathVariable String str){
        //调用业务层删除数据
        int rows=exchangeVarietyRateBiz.delete(str);
        return rows>0?"delete success":"delete failure";
    }
    //修改数据
    @PutMapping("/exch")
    public String updateFund(@RequestBody ExchangeVarietyRate exchangeVarietyRate){
        //调用业务层修改数据
        int rows=exchangeVarietyRateBiz.update(exchangeVarietyRate);
        return rows>0?"update success":"update failure";
    }
}
